import React from "react"

class TestComponent extends React.Component {
  // 定义组件状态
  state = {
    name: 'Hello'
  }
  count = {
    num: 0
  }
  // 事件
  changeName = () => {
    if (this.state.name === 'Hello') {
      this.setState({
        name: 'Hi'
      })
    } else {
      this.setState({
        name: 'Hello'
      })
    }
  }
  numAdd = () => {
    this.setState({
      num: this.count.num + 1
    })
  }
  render () {
    return (
      <div>
        This is a testComponent<br />
        当前name为{this.state.name}<br />
        <button onClick={this.changeName}>修改name</button><br />
        num: {this.count.num}<br />
        <button onClick={this.numAdd}>num++</button>
      </div>
    )
  }
}

function App () {
  return (
    <div>
      <TestComponent></TestComponent>
    </div>
  )
}

export default App
